import {WeaForm} from 'comsMobx';
import { observable, action, toJS } from 'mobx';
import { inject, observer} from 'mobx-react';
import React from 'react';
import {WeaNewScroll, WeaTools, WeaDialog } from 'ecCom';
import {Button, Row, Col} from 'antd';

@inject("myForm")
@observer
class Myform extends React.Component {
    constructor(props) {
        super(props);
    }

    /**
     * 生命周期方法，将要加载时执行
     */
    componentWillReceiveProps() {
        this.fngetSearchDatas();
    }

    componentWillMount() {
        this.fngetSearchDatas();
    }

    /**
     * 请求得到高级搜索数据
     */
    fngetSearchDatas = ( ) => {
        const { myForm,myParame} = this.props;
        const {form} = myForm;
        const {selectedKey, toptab} = myParame;
        if( !selectedKey || toptab.length < 1) {
            return ;
        }
        if (toptab[selectedKey] && toptab[selectedKey].condition && toptab[selectedKey].condition.condition) {
            form.setCondition( toptab[selectedKey].condition.condition );
        }
    }

    /**
     * 数据发生改变是执行，用于同步高级搜索的值到对应基础搜索框中
     * @param data
     */
    onChange(data) {
        if (data.name) {//只同步名称
            this.props.fnSetSearchContext(data.name.value);
        }
    }

    render() {
        const {myForm} = this.props;
        const { form} = myForm;
        return (
            <WeaNewScroll  onClick={() =>{this.props.fnSetSearchContext("")}}>
                {form && form.render(
                    { needTigger: true  },//添加center使变为一列显示
                    {
                        isHide: (key, formParams) => { let hide = false; return hide;}
                    })
                }
            </WeaNewScroll>
        )
    }
};

export default Myform;